﻿var Tree = Ext.tree;
//定义根节点的Loader 
var treeloader = new Tree.TreeLoader({
    url: '/dept.mvc/JsonTree'
    //baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI} //添加 uiProvider 属性
});
treeloader.on('beforeload', function (treeLoader, node) {
    treeLoader.baseParams.deptId = node.id;
});

//异步加载根节点
var rootnode = new Tree.AsyncTreeNode({
    id: '1',
    text: '太阳神直销总部'
});
var comboHidden = new Ext.form.Hidden({//保存父节点id
    id: 'comboHidden',
    name: 'comboHidden',
    value: ''
});
var comboxWithTree = new Ext.form.ComboBox({
    fieldLabel: '父级部门',
    name: 'pDept',
    id: 'pDept',
    anchor: '98%',
    allowBlank: false,
    typeAhead: true,
    selectOnFoucs: true,
    blankText: '请选择父级部门',
    emptyText: '请选择父级部门',
    store: new Ext.data.SimpleStore({ fields: [], data: [[]] }),
    editable: false,
    mode: 'local',
    triggerAction: 'all',
    maxHeight: 200,
    tpl: "<tpl for='.'><div style='height:200px'><div id='tree'></div></div></tpl>",
    selectedClass: '',
    onSelect: Ext.emptyFn
});
var tree = new Ext.tree.TreePanel({
    loader: treeloader,
    border: false,
    root: rootnode
});
tree.on('click', function (node) {
    comboxWithTree.setValue(node.text);
    comboHidden.setValue(node.id);
    comboxWithTree.collapse();
});
comboxWithTree.on('expand', function () {
    tree.render('tree');
});